package cn.tedu.cwgl.service.impl;

import cn.tedu.cwgl.entity.Card;
import cn.tedu.cwgl.entity.Item;
import cn.tedu.cwgl.mapper.CardMapper;
import cn.tedu.cwgl.service.CardService;
import cn.tedu.cwgl.util.PageModel;
import cn.tedu.cwgl.util.Result;
import cn.tedu.cwgl.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CardServiceImpl implements CardService {
    @Autowired
    CardMapper cardMapper;

    @Override
    public Result<Card> getCard(PageModel model) {
        List<Item> itemList = cardMapper.getCard(model);
        if (itemList.size() >= 0) {
            Result result = ResultUtil.success(itemList);
            result.setTotal(cardMapper.getCardTotal(model));
            if (result.getTotal() == 0) {
                result.setMsg("刷新重试");
            } else {
                result.setMsg("数据获取成功");
            }
            return result;
        } else {
            return ResultUtil.unSuccess("数据获取失败");
        }
    }

    @Override
    public List<Card> getCardType() {
        List<Card> cardType = cardMapper.getCardType();
        return cardType;
    }

    @Override
    public int updateCard(Card card) {
        return cardMapper.updateCard(card);
    }

    @Override
    public int delCard(int id) {
        return cardMapper.delCard(id);
    }

    @Override
    public int addCard(Card card) {
        return cardMapper.addCard(card);
    }
}
